package com.tfswx.ruleengine.compute.gzjy.felfunc;

import com.greenpineyu.fel.context.FelContext;
import com.tfswx.ruleengine.compute.gzjy.BaseFn;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * @author ricky
 * @date 2021/5/22
 */
public class Reg extends BaseFn {
    @Override
    public Object call(Object[] arguments, FelContext context) {
        String reg = String.valueOf(arguments[0]).replace("\\\\", "\\");
        String str = String.valueOf(arguments[1]);
        return Pattern.matches(reg, str);
    }

    @Override
    public String getZwmc() {
        return "正则匹配";
    }

    @Override
    public boolean isExport() {
        return true;
    }

    @Override
    public boolean isBuiltIn() {
        return true;
    }

    @Override
    public List<Param> getParams() {
        List<Param> params = new ArrayList<>();
        params.add(new Param("pattern"));
        params.add(new Param("content"));
        return params;
    }

    @Override
    public String getName() {
        return "reg";
    }
}
